package china.accountinghelper.database;

import java.util.Map;

import com.xdroid.base.SQLiteDALBase;

import android.content.ContentValues;
import android.database.Cursor;
import china.wc.tallyhelper.model.ModelBook;

/**
 * 操作ModelBook类的SQLiteDatabaseDAL类
 * 
 * 
 * 
 * @author 王超
 * 
 */
public class SQLiteDALModelBook extends SQLiteDALBase<ModelBook>
{

    public SQLiteDALModelBook(Class<ModelBook> pModelClass)
    {
        super(pModelClass);
    }

    @Override
    protected ContentValues toContentValues(ModelBook pModelBook)
    {
        Map<String, String> _FieldColumnMap = getFieldColumnMap();
        ContentValues _ContentValues = new ContentValues();

        for (String _FieldName : _FieldColumnMap.keySet()) {
            if ("mName".equals(_FieldName)) {
                _ContentValues.put(_FieldColumnMap.get(_FieldName), pModelBook.getName());
            } else if ("mCreateTime".equals(_FieldName)) {
                _ContentValues.put(_FieldColumnMap.get(_FieldName), pModelBook.getCreateTime().getTimeInMillis());
            } else if ("mState".equals(_FieldName)) {
                _ContentValues.put(_FieldColumnMap.get(_FieldName), pModelBook.getState());
            }
        }

        return _ContentValues;
    }

    @Override
    protected ModelBook toModel(Cursor pCursor)
    {
        ModelBook _ModelBook = new ModelBook();

        _ModelBook.setID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mID"))));
        _ModelBook.setName(pCursor.getString(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mName"))));
        _ModelBook.setCreateTime(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mCreateTime"))));
        _ModelBook.setState(pCursor.getInt(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mState"))));

        return _ModelBook;
    }

}
